<?php
define('LIB_PATH', str_replace("\\", DIRECTORY_SEPARATOR, dirname(__FILE__) . DIRECTORY_SEPARATOR));
define('ROOT_PATH', str_replace("library" . DIRECTORY_SEPARATOR, '', LIB_PATH));
define('ADDON_PATH', str_replace("library" . DIRECTORY_SEPARATOR, 'addon' . DIRECTORY_SEPARATOR, LIB_PATH));
define('CONFIG_PATH', str_replace("library" . DIRECTORY_SEPARATOR, 'config' . DIRECTORY_SEPARATOR, LIB_PATH));

// 配置文件
include CONFIG_PATH . 'config.php';
include CONFIG_PATH . 'data.php';
include CONFIG_PATH . 'smtp.php';
include CONFIG_PATH . 'map.php';

// 函数库
include_once LIB_PATH . 'lib.time.php';
include_once LIB_PATH . 'lib.base.php';
include_once LIB_PATH . 'lib.file.php';
include_once LIB_PATH . 'lib.url.php';
include_once LIB_PATH . 'library.php';

// ext
include_once LIB_PATH . 'lib.form.php';
include_once LIB_PATH . 'lib.sql.php';

// class
include_once LIB_PATH . 'cls.singleton.php';
include_once LIB_PATH . 'cls.logger.php';
include_once LIB_PATH . 'cls.model.php';
include_once LIB_PATH . 'cls.hook.php';
include_once LIB_PATH . 'cls.sql.php';
include_once LIB_PATH . 'cls.pdo.php';

// engine
$db = new DataObject();
$GLOBALS['db'] = &$db;

// cms_system
$cms = file_get('json', 'system');
$cms['language'] = 'zh-cn';
$cms['template'] = 'default';

// 语言
$_language = LANG_DIR . '/' . (!empty($_COOKIE['cms']['language']) ? $_COOKIE['cms']['language'] : $cms['language']) . '/';

// 加载语言
include ROOT_PATH . $_language . 'common.php';
include ROOT_PATH . $_language . 'admin.php';
include ROOT_PATH . $_language . 'priv.php';
$GLOBALS['lang'] = &$_lang;

// 闭站判断
if (!$cms['state'] && !is_admin()) {
  die($_lang['sys']['site_close']);
}

// 模板路径
$t_path = TPL_DIR;
$GLOBALS['t_path'] = &$t_path;

// addon
Hook::import(get_addon());

// admin
if (is_admin()) {
  include_once LIB_PATH . 'cls.dataops.php';
  include_once LIB_PATH . 'lib.admin.php';
}

// 默认分页结构
$cms['page_structure'] = json_decode(PAGE_STRUCTURE, true);
$GLOBALS['cms'] = &$cms;